package com.googlecode.cswish.struts.interceptor;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.apache.log4j.Logger;
import org.apache.struts2.ServletActionContext;

import com.googlecode.cswish.security.SafeManager;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;

/**
 * @author Jerry.Feng Date: 2008-01-13 05:07:05
 */
public class SecurityInterceptor extends AbstractInterceptor {
	
	private static final Logger logger = Logger
    		.getLogger(SecurityInterceptor.class);
	
	@Resource
	private SafeManager safeManager;
	
	@Override
	public String intercept(ActionInvocation invocation) throws Exception {
		
		ActionContext ac = invocation.getInvocationContext();
        HttpServletRequest request = (HttpServletRequest) ac.get(ServletActionContext.HTTP_REQUEST);
		boolean pass = safeManager.checkPageField((HttpServletRequest)request);
        
        if (pass) {
        	return invocation.invoke();
        } else {
        	return null;
        }
	}
}
